//index.js
//获取应用实例
const app = getApp()

Page({
  data: {
    motto: 'Hello World',
    userInfo: {},
    hasUserInfo: false,
    canIUse: wx.canIUse('button.open-type.getUserInfo'),
    root: app.globalData.root,
    realheight: 0,
    windowheight: 0,
  },
  //事件处理函数
  bindViewTap: function() {
    wx.navigateTo({
      url: '../logs/logs'
    })
  },
  bindTapP2:function(){
    wx.navigateTo({
      url: '../p2/p2',
    })
  },
  bindTapP3: function () {
    wx.navigateTo({
      url: '../p3-zhuce/zhuce',
    })
  }, 
   bindTapP4: function (object) {
    //  wx.getWeRunData({
    //    success:function(res){
    //      console.log(res); 
    //    }
    //  });
    //  wx.getLocation({
    //    type: 'gcj02', //返回可以用于wx.openLocation的经纬度
    //    success: function (res) {
    //      var latitude = res.latitude
    //      var longitude = res.longitude
    //      wx.openLocation({
    //        latitude: latitude,
    //        longitude: longitude,
    //        scale: 28
    //      })
    //    }
    //  })
    wx.navigateTo({
      url: '../p4-zhuce-yanzheng/zhuce-yz',
    })
  }, 
  bindTapP5: function () {
    wx.navigateTo({
      url: '../p5-biaodan/biaodan',
    })
  }, 
  bindTapP6: function () {
    wx.navigateTo({
      url: '../p6-save-share/save-share',
    })
  }, 
  bindTapP7: function () {
    wx.navigateTo({
      url: '../p7-now-adress/nowadress',
    })
  }, 
  bindTapP8: function () {
    wx.navigateTo({
      url: '../p8-camera/camera',
    })
  }, 
  onReady() {
    var that = this;
    if (that.data.once == false) {
      that.setData({
        once: true
      });
      setTimeout(() => {
        wx.createSelectorQuery().select('#container')
          .boundingClientRect(function (rect) {
            var rate = (app.globalData.windowHeight - 20) / rect.height;
            if (rate < 1) {
              that.setData({
                scale: rate
              })
            }
            that.setData({
              opacity: 1
            })
          }).exec()
      }, 300)
    }
  },
  onLoad: function () {
    if (app.globalData.userInfo) {
      this.setData({
        userInfo: app.globalData.userInfo,
        hasUserInfo: true
      })
    } else if (this.data.canIUse){
      // 由于 getUserInfo 是网络请求，可能会在 Page.onLoad 之后才返回
      // 所以此处加入 callback 以防止这种情况
      app.userInfoReadyCallback = res => {
        this.setData({
          userInfo: res.userInfo,
          hasUserInfo: true
        })
      }
    } else {
      // 在没有 open-type=getUserInfo 版本的兼容处理
      wx.getUserInfo({
        success: res => {
          app.globalData.userInfo = res.userInfo
          this.setData({
            userInfo: res.userInfo,
            hasUserInfo: true
          })
        }
      })
    }
  },
  getUserInfo: function(e) {
    console.log(e)
    app.globalData.userInfo = e.detail.userInfo
    this.setData({
      userInfo: e.detail.userInfo,
      hasUserInfo: true
    })
  }
})
